package com.eliza.vertx.library.tools

import io.vertx.core.Vertx
import io.vertx.core.Vertx.vertx
import io.vertx.ext.web.Router


/*-*- coding:utf-8 -*-
 * @Author  : debi
 * @Time    : 2/2/22
 * @Software: IntelliJ IDEA
 */
class VertxTools {
    companion object {
        fun result(
            vertx: Vertx, className: Any, funName: String,
            router: Router, port: Int,
        ) {
            vertx.createHttpServer().requestHandler(router)
                .listen(port)
                .onSuccess { hs ->
                    //控制台
                    println("--${className::class.java.name} || $funName Success ! : ${hs.actualPort()}")
                }.onFailure {
                    println("--${className::class.java.name} || $funName Fault ! :启动 失败了")
                }
        }

        fun runVerticalList(vertList: List<Class<*>>) {

            val vertx = vertx()
            vertList.forEach {
                println("class: ${it.name}")
                vertx.deployVerticle(it.name)
            }

        }

        fun runVertical(vertx: Class<*>) {

            vertx().deployVerticle(vertx.name)
            println("class: ${vertx.name}")

        }
    }
}